uname command
uname
- print system information
The uname
command in Linux is a simple utility that displays system information about the computer, such as the operating system name, kernel version, or hardware specifications. It’s useful for troubleshooting, scripting, or understanding the environment.
Usage: uname [OPTION]...
OPTION
: Flags that specify which system information to display.
Examples
-
Basic usage and options
Running
uname
without options prints the operating system name.$ uname
Linux- Output:
Linux
(on a Linux system). - This is the default behavior, showing the kernel name.
Use
-a
to get a full system summary.$ uname -a
Linux hostname 5.15.0-73-generic #80-Ubuntu SMP Mon May 15 15:42:23 UTC 2023 x86_64 GNU/Linux- Output:
Linux myhostname 5.15.0-73-generic #80-Ubuntu SMP Mon May 15 15:42:23 UTC 2023 x86_64 GNU/Linux
- Breakdown:
Linux
: Kernel namemyhostname
: Hostname5.15.0-73-generic
: Kernel release#80-Ubuntu SMP Mon May 15..
: Kernel version (build details)x86_64
: Machine hardware typeGNU/Linux
: Operating system
Combine flags to get multiple pieces of info.
$ uname -sr
Linux 5.15.0-73-generic- Output:
Linux 5.15.0-73-generic
(kernel name and release).
- Output:
-
Scripting with uname
uname
is often used in scripts to adapt behavior based on system details.#!/bin/bash
ARCH=$(uname -m)
echo "This system is running on $ARCH architecture."- Run it to see:
This system is running on x86_64 architecture.
- Run it to see:
To get help related to the uname
command use --help
option
$ uname --help
Usage: uname [OPTION]...
Print certain system information. With no OPTION, same as -s.
-a, --all print all information, in the following order,
except omit -p and -i if unknown:
-s, --kernel-name print the kernel name
-n, --nodename print the network node hostname
-r, --kernel-release print the kernel release
-v, --kernel-version print the kernel version
-m, --machine print the machine hardware name
-p, --processor print the processor type (non-portable)
-i, --hardware-platform print the hardware platform (non-portable)
-o, --operating-system print the operating system
--help display this help and exit
--version output version information and exit